package cn.edu.cug.cs.gtl.docsrv.auth.controller;

import cn.edu.cug.cs.gtl.docsrv.auth.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/api/auth/resource")
public class ResourceController {
    @Autowired
    ResourceService resourceService;
    /**
     * 传入资源名，获取资源信息，并转换成JSON传给前端
     * @param resourceName
     * @return
     */
    @GetMapping("/getResource")
    public  String getResource(
            @RequestParam(value = "resourceName") String resourceName){
        return resourceService.getResource(resourceName);
    }

    /**
     * 根据前端传入的资源名，删除后台中的资源
     * @param resourceName
     */
    @RequestMapping(value = "/deleteResource")
    public  void deleteResource(
            @RequestParam(value = "resourceName") String resourceName){
        resourceService.deleteResource(resourceName);
    }

    /**
     * 根据前端传入的资源的JSON字符串，更新后台中的资源
     * @param resourceJSON
     */
    @RequestMapping(value = "/updateResource")
    public void updateResource(
            @RequestParam(value = "resourceJSON") String resourceJSON){
        resourceService.updateResource(resourceJSON);
    }

    /**
     * 根据前端传入的资源的JSON字符串，在后台中插入该资源
     * @param resourceJSON
     */
    @RequestMapping(value = "/insertResource")
    public void insertResource(
            @RequestParam(value = "resourceJSON") String resourceJSON){
        resourceService.insertResource(resourceJSON);
    }
}
